using System;
using System.Globalization;

namespace Prometheus.Binding.ReadOnly.BaseConverters
{
    public class proIsToStringEquals : proChainConverter
    {
        public object EqualsTo { get; set; }

        public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == EqualsTo) return true;
            if (value == null || EqualsTo == null)
                return string.IsNullOrEmpty(value as string) == string.IsNullOrEmpty(EqualsTo as string);
            //not transparent, but good for jobs

            bool resit = value.ToString() == EqualsTo.ToString();
            return resit;
        }

        public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if ((bool) value) return value.ToString();
            return null;
        }
    }
}